<!--{template common/header_simple_start}-->
<link href="static/css/common.css?{VERHASH}" rel="stylesheet" media="all">
<script type="text/javascript" src="static/js/jquery.leftDrager.js?{VERHASH}"></script>
<style>
html,body{
	overflow:hidden;
	background:#FBFBFB;
}
.bs-left-container{
	width:120px;
}
.bs-main-container{
	margin-left:120px;
	overflow:auto;
}

</style>
<!--{template common/header_simple_end}-->

<div class="bs-container clearfix">
  <div class="bs-left-container  clearfix">
    <!--{template left}--> 
  </div>
  <div class="left-drager">
     <div class="left-drager-op"><div class="left-drager-sub"></div></div>
  </div>
      
  <div class="bs-main-container  clearfix" > 
      <div class="main-header">
      	 <ul  class="nav nav-pills nav-pills-bottomguide">
              <li><a href="{BASESCRIPT}?mod=setting&operation=qywechat">企业号绑定</a></li>
              <li><a href="{BASESCRIPT}?mod=setting&op=assistant">企业小助手</a></li>
              <li class="active"><a href="{BASESCRIPT}?mod=setting&op=wxsyn">数据同步</a></li>
        </ul>
    		
      </div>
      <div class="main-content" style="padding:15px">
                <ul class="help-block" style="line-height:2">
                	<li>一般只有初次绑定时才需要在此同步</li>
                    <li>同步操作会把本站的机构和部门及机构和部门下的用户同步到微信企业号</li>
                    <li>机构和用户管理里的操作会自动同步到微信端，不需要在此手工同步</li>
                    <li>此同步不会把微信企业号内的机构和部门及用户同步到本站</li>
                    <li>不在同步范围的用户，如果用户已经在微信中存在，将在微信中禁用此用户</li>
                </ul>
             	<button class="btn btn-width btn-info ml20" data-loading-text="正在同步,请稍后..." onclick="qywechat_syn_org(this)">开始同步到微信企业号</button>
      
                <div id="syn_info" class="alert"></div>
              
      </div>
  </div>
</div>
<script type="text/javascript">  
jQuery('.left-drager').leftDrager_layout();
function qywechat_syn_org(button,i){
	if(!i) i=0;
	var el=jQuery(button);
	if(i==0) el.button('loading');
	jQuery.getJSON('{ADMINSCRIPT}?mod=setting&op=wxsyn&do=qiwechat_syn_org&i='+i,function(json){
		if(json.error){
			el.html(json.error);
			window.setTimeout(function(){el.html('同步机构部门到微信企业号');el.button('reset');},1000);
		}else if(json.msg=='continue'){
			jQuery('#syn_info').append('<p>'+json.message+'</p>');
			jQuery('.bs-main-container').scrollTop(jQuery('.main-content').height());
			window.setTimeout(function(){qywechat_syn_org(button,json.start)},500);
		}else if(json.msg=='success'){
			jQuery('#syn_info').append('<p>机构和部门同步完成，正在同步用户...</p>');
			jQuery('.bs-main-container').scrollTop(jQuery('.main-content').height());
			qywechat_syn_user(button,0);
		}
	});
}
function qywechat_syn_user(button,i){
	if(!i) i=0;
	var el=jQuery(button);
	if(i==0) el.button('loading');
	jQuery.getJSON('{ADMINSCRIPT}?mod=setting&op=wxsyn&do=qiwechat_syn_user&i='+i,function(json){
		if(json.error){
			jQuery('#syn_info').append('<p>'+json.error+'</p>');
			window.setTimeout(function(){el.html('同步到微信企业号');el.button('reset');},1000);
		}else if(json.msg=='continue'){
			if(json.message) jQuery('#syn_info').append('<p>'+json.message+'</p>');
			jQuery('.bs-main-container').scrollTop(jQuery('.main-content').height());
			window.setTimeout(function(){qywechat_syn_user(button,json.start)},500);
		}else if(json.msg=='success'){
			jQuery('#syn_info').append('<p class="success">同步完成</p>');
			window.setTimeout(function(){el.html('同步到微信成功');},1000);
		}
	});
}
</script>
<script src="static/bootstrap/js/bootstrap.min.js?{VERHASH}"></script>

<!--{template common/footer_simple}-->
